package com.ldn.basic.enumeration;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 李大牛家的牛 (scafel@163.com) 
 * @createDate 2024/8/13 - 13:53
 * @description ...
 **/
@Schema(description = "订单状态")
@Getter
public enum OrderStatusEnum {

    UNPAID("UNPAID", "未支付"),
    PAID("PAID", "已支付"),
    REFUND("REFUND", "已退款"),
    CANCEL("CANCEL", "已取消"),
    EXPIRED("EXPIRED", "已过期"),
    FINISHED("FINISHED", "已完成"),
    WAIT_SHIP("WAIT_SHIP", "待发货"),
    SHIPPED("SHIPPED", "已发货"),
    RECEIVED("RECEIVED", "已收货"),
    EVALUATED("EVALUATED", "已评价"),
    CREATED("CREATED", "已创建"),
    RETURNED("RETURNED", "已退回"),
    UNKNOWN("UNKNOWN", "未知");
    ;

    private static final Map<String, OrderStatusEnum> codeToEnumMap = new HashMap<>();

    static {
        for (OrderStatusEnum type : OrderStatusEnum.values()) {
            codeToEnumMap.put(type.getCode(), type);
        }
    }

    private final String code;
    /**
     * 自定义描述
     **/
    private final String message;

    OrderStatusEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static OrderStatusEnum getType(String code) {
        OrderStatusEnum type = codeToEnumMap.get(code.toUpperCase());
        if (type == null) {
            return OrderStatusEnum.UNKNOWN;
        }
        return type;
    }

}
